package asd;

import asd.geometry.Geometry;
import asd.graphics.GObject;
import asd.graphics.GPosition;
import asd.graphics.GSegment;
import asd.graphics.GStyle;
import asd.graphics.GText;

/**
 * Classe utilizzata per la costruzione dell'albero sintattico decorato.
 * @author Giovanni Cammarata
 */
public class TestObject extends GObject
  {
    private TestObject  parent_;
    private double      x_, y_;
    private GSegment    circle_;
    private GSegment    line_;

    
    public TestObject (String name, GObject parent, double x, double y)
    {
      parent_ = parent instanceof TestObject ? (TestObject) parent : null;
      
      x_ = x;
      y_ = y;

      line_ = new GSegment();
      addSegment (line_);
      
      circle_ = new GSegment();
      addSegment (circle_);

      circle_.setText (new GText (name, GPosition.MIDDLE));

      setStyle (new GStyle());
      
      parent.add (this);
    }

    
    public double getX()
    {
      return x_;
    }


    public double getY()
    {
      return y_;
    }
    
    
    
    public void draw()
    {
      if (parent_ != null) 
        line_.setGeometry (parent_.getX(), parent_.getY(), x_, y_);
      
      circle_.setGeometryXy (Geometry.createCircle (x_, y_, 40.0));
    }
  }
